//
//  HSYPlayerVolumeView.m
//  高仿暴走斗图
//
//  Created by key on 16/8/19.
//  Copyright © 2016年 huangsongyao. All rights reserved.
//

#import "HSYPlayerVolumeView.h"
#import "HSYBaseVideoPlayerView.h"

static NSString *const kSystemVolumeDidChangeNotification   = @"AVSystemController_SystemVolumeDidChangeNotification";
static NSString *const kAudioVolumeNotificationParameter    = @"AVSystemController_AudioVolumeNotificationParameter";

#define VOLUME_MUTE     @""
#define VOLUME          @""

@interface HSYPlayerVolumeView ()

@property (nonatomic, strong, readwrite) UIImageView *volumeImageView;

@end

@implementation HSYPlayerVolumeView

- (instancetype)initWithLogo:(UIImage *)logo highLogo:(UIImage *)highLogo
{
    if (self = [super initWithLogo:logo highLogo:highLogo indicatorType:kHSYPlayerIndicatorProgessTypeVolume]) {
        
    }
    return self;
}

- (void)toPreventOverlap
{
    //防止重叠
    HSYBaseVideoPlayerView *playerView = (HSYBaseVideoPlayerView *)self.superview;
    playerView.timeIndicatorView.hidden = YES;
    playerView.brightnessIndicatorView.hidden = YES;
}

- (void)configScreenObserver
{
    @weakify(self);
    [[[[NSNotificationCenter defaultCenter] rac_addObserverForName:kSystemVolumeDidChangeNotification object:nil] deliverOn:[RACScheduler mainThreadScheduler]] subscribeNext:^(NSNotification *notification) {
        @strongify(self);
        float outputVolume = [[[notification userInfo] objectForKey:kAudioVolumeNotificationParameter] floatValue];
        [self updateIndicator:outputVolume];
    }];
}

- (void)updateUIConstraintByValue:(CGFloat)value
{
    if (value == kMinValue) {
        if (!self.volumeImageView.accessibilityIdentifier) {
            self.volumeImageView.accessibilityIdentifier = @"";
            self.volumeImageView.image = self.highLogo;
        }
    } else {
        if (self.volumeImageView.accessibilityIdentifier) {
            self.volumeImageView.accessibilityIdentifier = nil;
            self.volumeImageView.image = self.logo;
        }
    }
}

@end
